package com.atom.wifiupload.nanohttpd;

import android.util.Log;

import java.io.IOException;

/**
 * ============================================================
 * project: WIFI-Upload
 * package: com.atom.wifiupload.nanohttpd
 * fileDescribe:
 * user: admin
 * email: 1299854942@qq.com
 * createTime: 2017/6/24  09:52
 * modify:
 * version:: V1.0
 * ============================================================
 **/
public class ServerRunner {

    private static SimpleFileServer server;
    public static boolean serverIsRunning = false;

    /**
     * 启动wifi传书服务
     */
    public static void startServer() {
        server = SimpleFileServer.getInstance();
        try {
            if (!serverIsRunning) {
                server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
                serverIsRunning = true;
                Log.e("ServerRunner", "start server:\n");
            }
        } catch (IOException e) {
            e.printStackTrace();

        }
    }

    public static void stopServer() {
        if (server != null) {
            server.stop();
            serverIsRunning = false;
            Log.e("ServerRunner", "Server stopped.\n");
        }
    }

}

